home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / textra16.lha / Textra116 / Scripts / JForth_Scripts / zDotIf.textra < prev   
Encoding:
Text File  |  1994-01-28  |  2.7 KB  |  103 lines

  1.      /******************************************************************
  2.      *   TEXTRA AREXX script -- Mike Haas, 1991, All Rights Reserved.  *
  3.      * Freely distributable ONLY as a component of the TEXTRA package. *
  4.      * This banner may not be removed or altered (improvements to the  *
  5.      *    actual program welcome).  Please document and send to me.    *
  6.      *        !!! PLACE THIS FILE IN YOUR REXX: DIRECTORY !!!          *
  7.      ******************************************************************/
  8.  
  9. /*
  10. ** zDotIf.textra   Mike Haas
  11. **
  12. ** Convienient for disabling sections of code in Forth from being
  13. ** acted on by the interpreter/compiler.  It adds "0 .IF" and a ".THEN"
  14. ** around the selected lines, and by default, includes them within a
  15. ** [ and ] characters, so that the statements are appropriate for
  16. ** use while compiling.  (For JForth, these statements are very
  17. ** similar to "#if 0" and "#endif" are to C.)
  18. **
  19. ** To have this script insert statements suitable for the interpreter,
  20. ** (in other words, not enclosed within [ and ]), provide any argument.
  21. ** It doesn't matter what it is; it is the lack of an argument which
  22. ** triggers the [ and ] encapsulation.
  23. **
  24. ** Just select some lines of text and enter:   zDotIf
  25. **
  26. **                                                    or...
  27. **
  28. **                                             zDotIf <anything>
  29. **
  30. ** Note that if you select text which contains "0 .IF" or "[ 0 .IF ]"
  31. ** for the first line, this script will assume that the last selected
  32. ** line is the corresponding .THEN statement.  It will then delete the
  33. ** first and last selected lines, re-enabling that text to the JForth
  34. ** compiler/interpreter.
  35. */
  36.  
  37. OPTIONS results
  38.  
  39. rex = 0; result = "NOTSUPPORTED"    /*00001*/
  40. textraversion
  41. parse var result maj min rex
  42. if (result == "NOTSUPPORTED") | (rex < 3) then do
  43.     notify "Textra V1.13 or later required for this script."
  44.     exit
  45. end
  46.  
  47. parse arg nobracket
  48.  
  49. get select position
  50.  
  51. if (result == "NO SELECT") then   /* is nothing selected? */
  52.  
  53.     do
  54.         notify "There must be a select range to comment/uncomment."
  55.         exit
  56.     end
  57.  
  58.  
  59. /* yes, there is a selection, get it's boundaries */
  60. parse var result   startx ' ' starty ' ' endx ' ' endy
  61.  
  62. currx = startx
  63. curry = starty
  64.  
  65. /* if nothing on the endline is actually selected, don't include it */
  66. if (endx == 0) then  endy = endy - 1
  67.  
  68.  
  69. /*
  70. ** check if we are to delete an existing set
  71. */
  72.  
  73. get line starty
  74. if (result = "0 .IF") | (result = "[ 0 .IF ]") then do
  75.  
  76.     /*
  77.     ** yep, take it out
  78.     */
  79.     selectline endy
  80.     del
  81.     selectline starty
  82.     del
  83.     
  84. end
  85. else do
  86.  
  87.     /*
  88.     ** nope, put 'em in
  89.     */
  90.     line starty
  91.     if (nobracket ~= "") then
  92.         textn "0 .IF"
  93.     else
  94.         textn "[ 0 .IF ]"
  95.  
  96.     line endy+2
  97.     if (nobracket ~= "") then
  98.         textn ".THEN"
  99.     else
  100.         textn "[ .THEN ]"
  101.  
  102. end
  103.